#! /bin/bash
SQOOP_HOME=/usr/bin/sqoop


#上个月1日
if [[ $1 == "" ]];then
    Last_Month_DATE=$(date -d "$(date +%Y%m)01 last month" +%Y-%m-01)
else
    Last_Month_DATE=$1
fi

V_PARYEAR=`date --date="$Last_Month_DATE" +%Y`

mysql -uroot -p123456 scrm_bi -e "
delete from itcast_clue where yearinfo = '${V_PARYEAR}
"

${SQOOP_HOME} export \
--connect "jdbc:mysql://192.168.10.150:3306/scrm_bi?useUnicode=true&characterEncoding=utf-8" \
--username root \
--password 123456 \
--table itcast_clue \
--hcatalog-database itcast_dws \
--hcatalog-table itcast_clue_dws \
--hcatalog-partition-keys yearinfo  \
--hcatalog-partition-values ${V_PARYEAR} \
-m 4